<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north'" style="height:40px">
		<div style="float:left;padding:5px 0 0 5px;">
			<a href="javascript:void(0)" onclick="$('#conditionWin4').window('open');" class="easyui-linkbutton" data-options="iconCls:'icon-search'">筛选学生</a>
			<span style="margin-left:20px;height:20px;">当前筛选条件：</span>
			<span id="currentCondition" style="display:inline-block;vertical-align:sub;color:red;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;width:250px;">全部学生</span>
		</div>
	</div>
    <div data-options="region:'west',split:true" style="width:480px;">
    	<table class="easyui-datagrid" id="studentList2" 
    		data-options="url:'user/students',fit:true,fitColumns:true,rownumbers:true,pagination:true,pageSize:20,pageList:[20,50,100,200,500,1000],
    			toolbar:leftToolbar">
    		<thead>
		        <tr>
		        	<th data-options="field:'ck',checkbox:true"></th>
		            <th data-options="field:'xm',halign:'center',width:60">姓名</th>
		            <th data-options="field:'lqyxsmc',halign:'center',width:120">系名称</th>
		            <th data-options="field:'cwbh',align:'center',width:80">财务编号</th>
		            <th data-options="field:'lqzymc',halign:'center',width:130">主修专业</th>
		            <th data-options="field:'xh',halign:'center',width:60">学号</th>
		        </tr>
		    </thead>
    	</table>
    </div>
    <div data-options="region:'center'">
    	<table class="easyui-datagrid" id="graduates" data-options="url:'user/graduates',fit:true,fitColumns:true,rownumbers:true,toolbar:rightToolbar,
    		pagination:true,pageSize:20,pageList:[20,50,100,200,500,1000]">
    		<thead>
		        <tr>
		        	<th data-options="field:'ck',checkbox:true"></th>
		            <th data-options="field:'xm',width:$(this).width() * 0.1,halign:'center'">姓名</th>
		            <th data-options="field:'lqyxsmc',width:$(this).width() * 0.2,halign:'center'">系名称</th>
		            <th data-options="field:'cwbh',align:'center',width:$(this).width() * 0.15">财务编号</th>
		            <th data-options="field:'lqzymc',width:$(this).width() * 0.2,halign:'center'">主修专业</th>
		            <th data-options="field:'xh',width:$(this).width() * 0.2,halign:'center'">学号</th>
		        </tr>
		    </thead>
    	</table>
    </div>
</div>

<div id="conditionWin4" class="easyui-window" title="请选择学生的筛选条件" style="width:460px;height:380px;padding-left:30px;padding-top:20px;"
        data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
        <table class="form_table" style="border:0px;">
        	<tr><td>系：</td><td><input class="easyui-combobox" id="college4" style="width:240px;" value="-"
            data-options="multiple:true,url:'uni/colleges',valueField:'lqyxsm',textField:'lqyxsmc',onSelect:checkIfAll,onHidePanel:cascadeMajor
            	,loadFilter:function(data){return _.union([{id:0,lqyxsm:'-',lqyxsmc: '不限'}],data);}"></td></tr>
            <tr><td>专业：</td><td><input class="easyui-combobox" id="major4" style="width:240px;" value="-" 
            data-options="multiple:true,url:'uni/majors',valueField:'lqzydm',textField:'lqzymc',onSelect:checkIfAll
            	,loadFilter:function(data){return _.union([{id:0,lqzydm:'-',lqzymc: '不限'}],data);}"></td></tr>
            <tr><td>年级：</td><td><input class="easyui-combobox" id="year4" style="width:240px;" value="-" 
            data-options="multiple:true,url:'grant/years',valueField:'id',textField:'value',panelHeight:110,onSelect:checkIfAll
            	,loadFilter:function(data){return _.union([{id:'-',value: '不限'}],data);}"></td></tr>
            <tr><td>类别：</td><td><input class="easyui-combobox" id="classify4" style="width:240px;" value="-" 
            data-options="multiple:true,url:'grant/classify',valueField:'id',textField:'value',panelHeight:110,onSelect:checkIfAll
            	,loadFilter:function(data){return _.union([{id:'-',value: '不限'}],data);}"></td></tr>
            <tr><td>所属名单：</td><td><input class="easyui-combobox" id="groupId4" style="width:240px;" value="-" 
            data-options="multiple:true,url:'user/group',valueField:'id',textField:'name',panelHeight:110,onSelect:checkIfAll
            	,loadFilter:function(data){return _.union([{id:'-',name: '不限'}],data);}"></td></tr>
            <tr><td></td><td><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="refreshStudents()">确定</a>
            	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="$('#conditionWin4').window('close');">取消</a></td></tr>
        </table>
</div>

<script type="text/javascript" src="statics/js/xdate.js"></script>
<script>

var xhs = new Array();
var leftToolbar = [{
    text:'设为毕业生',
    iconCls:'icon-add',
    handler:function(){
        var checkedList = $('#studentList2').datagrid('getChecked');
        if(checkedList.length == 0) {
			$.messager.alert('提示','请至少选择一个非毕业生！');
			return;
        }
        $.ajax({
			url:'user/inGraduates?xhs=' + $.map(checkedList,function(row){return row.xh;}).join(','),
			success:function(result) {
				if(result.errorInfo != 'none') {
					$.messager.alert('提示',result.errorInfo);
					return;
				} 
				reloadAll();
				$.messager.alert('提示','已成功将所选学生转为毕业生！');
				
			}
		});
		
        
    }
}];
var rightToolbar = [{
    text:'撤销毕业生',
    iconCls:'icon-remove',
    handler:function(){
        var checkedList = $('#graduates').datagrid('getChecked');
        if(checkedList.length == 0) {
        	$.messager.alert('提示','请至少选择一个毕业生！');
			return;
        }
        $.ajax({
			url:'user/outGraduates?xhs=' + $.map(checkedList,function(row){return row.xh;}).join(','),
			success:function(result) {
				if(result.errorInfo != 'none') {
					$.messager.alert('提示',result.errorInfo);
					return;
				} 
				reloadAll();
				$.messager.alert('提示','已成功将所选毕业生还原！');
			}
		});
    }
}];

function checkIfAll(record) {
	if(record[$(this).combobox('options').valueField] == '-') {
		$(this).combobox('setValue','-');
	} else {
		$(this).combobox('unselect','-');
	}
}

function cascadeMajor() {
	var college = $('#college4').combobox('getValues').join(',');
	$('#major4').combobox('reload','uni/majors' + (college == '-'? '':'?college=' + college));
}

function refreshStudents() {
	var info = '学院:' + $('#college4').combobox('getText') + ',' +
			'专业:' + $('#major4').combobox('getText') + ',' +
			'年级:' + $('#year4').combobox('getText') + ',' +
			'类别:' + $('#classify4').combobox('getText') + ',' +
			'所属名单:' + $('#groupId4').combobox('getText');
	$('#currentCondition').html(info);
	$('#currentCondition').attr('title',info);

	reloadStudents();

	$('#conditionWin4').window('close');
}

function reloadStudents() {
	$('#studentList2').datagrid('reload',
			{college:$('#college4').combobox('getValues').join(','),
			major:$('#major4').combobox('getValues').join(','),
			year:$('#year4').combobox('getValues').join(','),
			classify:$('#classify4').combobox('getValues').join(','),
			groupId:$('#groupId4').combobox('getValues').join(','),});
}

function reloadGraduates() {
	$('#graduates').datagrid('reload');
}

function reloadAll() {
	reloadStudents();
	reloadGraduates();
}
</script>